/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow-x: hidden;
}

/* Main container - responsive height based on environment */
#main-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    position: relative;
    overflow: hidden;
}

/* Detect if running in full window vs iframe */
@media (min-height: 500px) {
    body:not(.iframe-mode) #main-container {
        height: 90vh;
    }
}

/* Screen management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* Welcome Screen Styles */
#welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.welcome-content {
    max-width: 400px;
    padding: 20px;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.welcome-content h2 {
    color: #4a5568;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.welcome-content p {
    color: #718096;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.name-input-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#student-name {
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
    text-align: center;
}

#student-name:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#start-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px; /* Touch-friendly */
}

#start-btn:enabled:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Question Screen Styles */
#question-screen {
    padding: 15px;
    overflow-y: auto;
}

.progress-bar {
    background: white;
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

.progress-fill {
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.8rem;
    color: #718096;
    margin-top: 5px;
    display: block;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.category-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    position: relative;
}

.category-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    position: relative;
}

.category-icon {
    font-size: 1.5rem;
}

.category-header h3 {
    font-size: 1rem;
    color: #4a5568;
    flex: 1;
}

.completion-badge {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #e2e8f0;
    transition: all 0.2s;
}

.completion-badge.completed {
    background: #48bb78;
    position: relative;
}

.completion-badge.completed::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 10px;
    font-weight: bold;
}

.questions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.question-btn {
    padding: 10px 12px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    line-height: 1.3;
    min-height: 44px; /* Touch-friendly */
    display: flex;
    align-items: center;
}

.question-btn:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.question-btn.answered {
    background: #e6fffa;
    border-color: #38b2ac;
    color: #234e52;
}

.generate-section {
    text-align: center;
    padding: 15px 0;
}

#generate-map-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

#generate-map-btn:enabled:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

#generate-map-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.modal-header h3 {
    color: #4a5568;
    font-size: 1.1rem;
    line-height: 1.4;
    flex: 1;
    margin-right: 15px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #a0aec0;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-btn:hover {
    background: #f7fafc;
    color: #4a5568;
}

.modal-body {
    padding: 20px;
}

#answer-input {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    transition: border-color 0.2s;
}

#answer-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.char-counter {
    text-align: right;
    font-size: 0.8rem;
    color: #a0aec0;
    margin-top: 5px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #e2e8f0;
    text-align: right;
}

#save-answer-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 40px;
}

#save-answer-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Map Screen Styles */
#map-screen {
    padding: 15px;
}

.map-controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.map-controls button {
    padding: 8px 16px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    min-height: 36px;
}

.map-controls button:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
}

#concept-map-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    height: calc(100% - 60px);
    overflow: hidden;
}

#concept-map {
    width: 100%;
    height: 100%;
}

/* Concept Map Elements */
.map-node {
    cursor: pointer;
    transition: all 0.2s;
}

.map-node:hover .node-circle {
    stroke-width: 3;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.node-circle {
    stroke: #4a5568;
    stroke-width: 2;
    transition: all 0.2s;
}

.central-node .node-circle {
    fill: #667eea;
}

.category-node .node-circle {
    fill: #48bb78;
}

.answer-node .node-circle {
    fill: #ed8936;
}

.node-text {
    font-family: 'Segoe UI', sans-serif;
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: central;
    fill: white;
    font-weight: 600;
    pointer-events: none;
}

.map-link {
    stroke: #a0aec0;
    stroke-width: 2;
    fill: none;
    opacity: 0.7;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s;
    max-width: 200px;
    line-height: 1.3;
}

.tooltip.visible {
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .categories-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    
    .welcome-content {
        padding: 15px;
    }
    
    .welcome-content h2 {
        font-size: 1.3rem;
    }
    
    .category-card {
        padding: 12px;
    }
    
    .question-btn {
        font-size: 0.8rem;
        padding: 8px 10px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .question-btn,
    #start-btn,
    #generate-map-btn,
    #save-answer-btn {
        min-height: 48px; /* Larger touch targets */
    }
    
    .close-btn {
        width: 40px;
        height: 40px;
    }
}